app.controller('BusCityModalCtrl', function ($scope, $modalInstance, param, toaster) {

	$scope.param = param;
	if ($scope.param.data == null) $scope.param.data = {};

	$scope.list = arrCity;
	console.log($scope.list);
	for (var i = 0; i < $scope.list.length; i++) {
		if ($scope.list[i].name == "其它") {
			$scope.list.splice($scope.list.indexOf($scope.list.name), 1);
		}
		if ($scope.list[i].name == "海外") {
			$scope.list.splice($scope.list.indexOf($scope.list.name), 1);
		}
	}
	$scope.provinceList = $scope.list;
	$scope.provinceList.selected = $scope.provinceList[0];
	if ($scope.param.type == 'update') {
		for (var j = 0; j < $scope.provinceList.length; j++) {
			var p = $scope.provinceList[j];
			if ($scope.param.data.province == p.name) {
				$scope.provinceList.selected = $scope.provinceList[j];
				break;
			}
		}
	}

	$scope.ok = function () {
		if ($scope.myForm.$valid) {
			if ($scope.param.type == "update" && !$scope.param.data.initial) {
				toaster.pop('warning', '提示', '城市名首字母不可为空！');
				return;
			}
			if ($scope.param.type == "insert") {
				if ($scope.provinceList.selected.name == "请选择") {
					toaster.pop('warning', '提示', '请选择省份！');
					return;
				} else {
					$scope.param.data.province = $scope.provinceList.selected.name;
				}
			} else if ($scope.param.type == "update") {
				if ($scope.provinceList.selected.name != "请选择") {
					$scope.param.data.province = $scope.provinceList.selected.name;
				}
			}
			$modalInstance.close($scope.param);
		}
	};

	$scope.cancel = function () {
		$modalInstance.dismiss('cancel');
	};
});